package com.tron.dobest.validation;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;


import javax.validation.constraints.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * {
 * "a":"1",
 * "b":["1","2"],
 * "c":"1@1.com",
 * "d":1,
 * "g":[""]
 * }
 * <p>
 * 默认为default分组，并且在主注解验证通过时才验证default分组
 * <p>
 * 指定分组校验参见{@link TronValidateController }
 */

@Data
public class ValidateData {

    @NotEmpty(message = "a字符不能为空，不能为null", groups = {Add.class})    //分组包含Add.class时校验
    private String a;

    @NotNull(message = "b字符数组不能为null")                   //默认校验
    private String[] b;

    @NotEmpty(message = "c邮件地址不能为空", groups = {Update.class})     //分组包含Update.class时校验
    @Email(message = "c邮件地址不合法", groups = {Update.class})          //分组包含Update.class时校验
    private String c;

    @NotNull(message = "d数值不能为null")            //分组包含Default.class时校验
    @Min(value = 1, message = "d最小值为1")           //分组包含Default.class时校验
    private Integer d;

    @NotNull(message = "e时间不能为空", groups = {Other.class, Add.class}) //分组包含Other.class或者Add.class时校验
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime e;

    private Date f;                      //不校验

    @NotEmpty(message = "g集合不能为空")               //分组包含Default.class时校验
    private List g;
}
